package org.java.assembler;

public class Code {
    public Bits dest(String dest) {
        if (dest == null) {
            return Bits.createBits("000");
        }
        switch (dest) {
            case "M" :
                return Bits.createBits("001");
            case "D":
                return Bits.createBits("010");
            case "MD":
                return Bits.createBits("011");
            case "A":
                return Bits.createBits("100");
            case "AM":
                return Bits.createBits("101");
            case "AD":
                return Bits.createBits("110");
            case "AMD":
                return Bits.createBits("111");
            default:
                return Bits.createBits("000");
        }
    }

    public Bits comp(String comp) {
        if (comp == null) {
            return Bits.createBits("0000000");
        }
        switch (comp) {
            case "0":
                return Bits.createBits("0101010");
            case "1":
                return Bits.createBits("0111111");
            case "-1":
                return Bits.createBits("0111010");
            case "D":
                return Bits.createBits("0001100");
            case "A":
                return Bits.createBits("0110000");
            case "!D":
                return Bits.createBits("0001101");
            case "!A":
                return Bits.createBits("0110001");
            case "-D":
                return Bits.createBits("0001111");
            case "-A":
                return Bits.createBits("0110011");
            case "D+1":
                return Bits.createBits("0011111");
            case "A+1":
                return Bits.createBits("0110111");
            case "D-1":
                return Bits.createBits("0001110");
            case "A-1":
                return Bits.createBits("0110010");
            case "D+A":
                return Bits.createBits("0000010");
            case "D-A":
                return Bits.createBits("0010011");
            case "A-D":
                return Bits.createBits("0000111");
            case "D&A":
                return Bits.createBits("0000000");
            case "D|A":
                return Bits.createBits("0010101");
            case "M":
                return Bits.createBits("1110000");
            case "!M":
                return Bits.createBits("1110001");
            case "-M":
                return Bits.createBits("1110011");
            case "M+1":
                return Bits.createBits("1110111");
            case "M-1":
                return Bits.createBits("1110010");
            case "D+M":
                return Bits.createBits("1000010");
            case "D-M":
                return Bits.createBits("1010011");
            case "M-D":
                return Bits.createBits("1000111");
            case "D&M":
                return Bits.createBits("1000000");
            case "D|M":
                return Bits.createBits("1010101");
            default:
                return Bits.createBits("0000000");
        }
    }

    public Bits jump(String jump) {
        if (jump == null) {
            return Bits.createBits("000");
        }
        switch (jump) {
            case "JGT":
                return Bits.createBits("001");
            case "JEQ":
                return Bits.createBits("010");
            case "JGE":
                return Bits.createBits("011");
            case "JLT":
                return Bits.createBits("100");
            case "JNE":
                return Bits.createBits("101");
            case "JLE":
                return Bits.createBits("110");
            case "JMP":
                return Bits.createBits("111");
            default:
                return Bits.createBits("000");
        }
    }
}
